﻿Imports System.IO
Imports Transcriber.Api

''' <summary>
''' Settings dialog for the ModeFileTranscriber plug-in
''' </summary>
Public Class frmModeFileTranscriberSettings

    Private mPlugin As ModeFileTranscriber

    ''' <summary>
    ''' Initializes a new instance of the <see cref="frmModeFileTranscriberSettings" /> class.
    ''' </summary>
    ''' <param name="plugin">The plugin.</param>
    Public Sub New(ByVal plugin As ModeFileTranscriber)

        Me.InitializeComponent()
        mPlugin = plugin

    End Sub

    ''' <summary>
    ''' Handles the Load event of the frmModeFileTranscriberSettings control.
    ''' </summary>
    ''' <param name="sender">The source of the event.</param>
    ''' <param name="e">The <see cref="System.EventArgs" /> instance containing the event data.</param>
    Private Sub frmModeFileTranscriberSettings_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim modeDirectory As New DirectoryInfo(Me.mPlugin.ModeDirectory)

        For Each modeFile As FileInfo In modeDirectory.GetFiles("*.mod")

            Dim mode As String = modeFile.Name.Substring(0, modeFile.Name.Length - 4)
            Me.lstModes.Items.Add(mode)

            If Not IsNothing(Me.mPlugin.CurrentMode) And Me.mPlugin.CurrentMode = mode Then
                Me.mPlugin.CurrentMode = mode
                Me.lstModes.SelectedIndex = Me.lstModes.Items.Count - 1
            End If

        Next

        Me.mPlugin.LoadMode()

    End Sub

    ''' <summary>
    ''' Handles the SelectedIndexChanged event of the lstModes control.
    ''' </summary>
    ''' <param name="sender">The source of the event.</param>
    ''' <param name="e">The <see cref="System.EventArgs" /> instance containing the event data.</param>
    Private Sub lstModes_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstModes.SelectedIndexChanged

        Me.mPlugin.CurrentMode = Me.lstModes.SelectedItem.ToString()
        Me.mPlugin.LoadMode()
        My.Settings.ModeFile = Me.mPlugin.CurrentMode

    End Sub

    ''' <summary>
    ''' Handles the Click event of the btnNumerals control.
    ''' </summary>
    ''' <param name="sender">The source of the event.</param>
    ''' <param name="e">The <see cref="System.EventArgs" /> instance containing the event data.</param>
    Private Sub btnNumerals_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNumerals.Click

        Using dialog As New frmTengwarNumerals(mPlugin.Transcriber)

            dialog.ShowDialog()

        End Using

    End Sub

    ''' <summary>
    ''' Handles the Click event of the btnEditMode control.
    ''' </summary>
    ''' <param name="sender">The source of the event.</param>
    ''' <param name="e">The <see cref="System.EventArgs" /> instance containing the event data.</param>
    Private Sub btnEditMode_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditMode.Click

        Using dialog As New frmEditMode(Me.lstModes.SelectedItem, Me.mPlugin.Transcriber)

            dialog.ShowDialog()

        End Using

    End Sub

    ''' <summary>
    ''' Handles the Click event of the btnNewMode control.
    ''' </summary>
    ''' <param name="sender">The source of the event.</param>
    ''' <param name="e">The <see cref="System.EventArgs" /> instance containing the event data.</param>
    Private Sub btnNewMode_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewMode.Click

        Using dialog As New frmEditMode(Nothing, Me.mPlugin.Transcriber)

            dialog.ShowDialog()

        End Using

    End Sub

    ''' <summary>
    ''' Handles the Click event of the btnOk control.
    ''' </summary>
    ''' <param name="sender">The source of the event.</param>
    ''' <param name="e">The <see cref="System.EventArgs" /> instance containing the event data.</param>
    Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click

        Me.Close()

    End Sub

End Class